//
//  MessageViewController.m
//  Yu01
//
//  Created by 蒋松涵 on 16/8/23.
//  Copyright © 2016年 蒋松涵. All rights reserved.
//

#import "MessageViewController.h"
#import "ViewController.h"

@interface MessageViewController ()<UITableViewDataSource,UITableViewDelegate>

//宏定义有代理的alertView
#define ALERT_DEL(msg) UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];\
[alert show];

@property (nonatomic,strong)UITableView * tableview;
@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.tableFooterView = [[UITableView alloc]init];
    [self.view addSubview:self.tableview];
}
//区数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 7;
}
//每区几行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 1;
    }
    else if (section == 1)
    {
        return 1;
    }
    else if (section == 2)
    {
        return 1;
    }
    else if (section == 3)
    {
        return 1;
    }
    else if (section == 4)
    {
        return 1;
    }
    else if (section == 5)
    {
        return 1;
    }
    else
    {
        return 1;
    }
}
//
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //定义唯一标示
    static NSString * CellIdentifier = @"cell";
    //通过唯一标示创建cell实例
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //初始化
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    
    if (indexPath.section == 0)
    {
        cell.textLabel.text = @"密码重置";
    }
    else if (indexPath.section == 1)
    {
        cell.textLabel.text = @"个人信息";
    }
    else if (indexPath.section == 2)
    {
        cell.textLabel.text = @"意见反馈";
    }
    else if (indexPath.section == 3)
    {
        cell.textLabel.text = @"关于";
    }
    else if (indexPath.section == 4)
    {
        cell.textLabel.text = @"清除缓存";
//        NSUInteger totalSize = [[SDImageCache sharedImageCache]getSize];
//        CGFloat cacheSize = totalSize/1024.0/1024.0;
//        cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2fM",cacheSize];
    }
    else if (indexPath.section == 5)
    {
        cell.textLabel.text = @"网络播放设置";
    }
    else
    {
        cell.textLabel.text = @"退出登录";
    }
    return cell;
}
//cell的点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        //密码重置
    }
    else if (indexPath.section == 1)
    {
        //个人信息
    }
    else if (indexPath.section == 2)
    {
        //意见反馈
    }
    else if (indexPath.section == 3)
    {
        //关于
    }
    else if (indexPath.section == 4)
    {
        //清除缓存
//        [self clearTotalCacheAction];
    }
    else if (indexPath.section == 5)
    {
        //网络播放设置
    }
    else
    {
        //退出登录
        ALERT_DEL(@"是否注销登录？");
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        ViewController * VC = [[ViewController alloc]init];
        [self presentViewController:VC animated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
